package cn.iocoder.yudao.module.handguard.dal.mysql.user;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.handguard.controller.admin.client.vo.UserAllocationReqVo;
import cn.iocoder.yudao.module.handguard.controller.admin.client.vo.UserPageReqVO;
import cn.iocoder.yudao.module.handguard.controller.admin.order.vo.UserResVo;
import cn.iocoder.yudao.module.handguard.controller.admin.statistics.vo.PerformanceStatisticsResVO;
import cn.iocoder.yudao.module.handguard.controller.admin.userdb.vo.UserRoleListVO;
import cn.iocoder.yudao.module.handguard.controller.app.user.vo.AgentUserResVo;
import cn.iocoder.yudao.module.handguard.dal.dataobject.user.UserDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 推荐人记录 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface MiniUserMapper extends BaseMapperX<UserDO> {

    default PageResult<UserDO> selectPage(UserPageReqVO reqVO) {
        String [] typeArr = reqVO.getUserType().split(",");
        // 分页查询
        return selectPage(reqVO, new LambdaQueryWrapperX<UserDO>()
                .eqIfPresent(UserDO::getStatus,reqVO.getStatus())
                .betweenIfPresent(UserDO::getLoginDate, reqVO.getLoginDate())
                .betweenIfPresent(UserDO::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(UserDO::getUserType,typeArr)
                .like(StringUtils.isNotEmpty(reqVO.getAgentName()),UserDO::getAgentName,reqVO.getAgentName())
                .like(StringUtils.isNotEmpty(reqVO.getWarrantName()),UserDO::getWarrantName,reqVO.getWarrantName())
                .like(StringUtils.isNotEmpty(reqVO.getNickname()),UserDO::getNickname, reqVO.getNickname())
                .like(StringUtils.isNotEmpty(reqVO.getMobile()),UserDO::getMobile, reqVO.getMobile())
                .like(StringUtils.isNotEmpty(reqVO.getName()),UserDO::getName, reqVO.getName())
                .orderByDesc(UserDO::getId));
    }

    UserResVo getUserById(@Param("id") Long id);

    int addUserRole(@Param("userId") Long userId,@Param("role") Long role,@Param("date") Date date,@Param("id") Long id);

    int deleteUserRole(@Param("userId") Long userId);

    int updateUserAgent(@Param("userId") Long userId,@Param("id")Long id, @Param("name")String name,@Param("dbNumber")String dbNumber);

    int updateUserWarrant(@Param("userId") Long userId,@Param("id")Long id, @Param("name")String name,@Param("dbNumber")String dbNumber);


    //后端首页统计相关
    int countNowUser();

    int countOrder();

    int selectQuota();

    BigDecimal countCj();

    PerformanceStatisticsResVO getPerformanceStatistics(@Param("year") int year);

    UserDO getUserInfo(@Param("userId") Long userId);

    void affirmUser(@Param("userId")Long userId,@Param("code") Long code);

    void setUserQrCode(@Param("userId")Long userId,@Param("imgUrl")String imgUrl);

    List<AgentUserResVo> getAgentList();

    int checkIdCard(@Param("idCard")String idCard);

    void updateIdCard(@Param("userId") Long userId, @Param("idCard") String idCard);

    List<UserRoleListVO> getUserRoleList(@Param("userId") Long userId);

    List<String> getDeptIdList(@Param("deptId") Long deptId);

    List<String> getDeptUserIdList(@Param("deptList")List<String> deptList,@Param("userType")String userType);

    List<UserDO> selectUserReferrerListByUserId(@Param("userId") Long userId);
}
